#ifndef REDISADAPTER_COMMAND_IN_H_
#define REDISADAPTER_COMMAND_IN_H_
#include "command.h"

#pragma pack(1)
namespace Cmd {
        namespace RedisAdapter {
                //  cmd declaration
                enum {
                        CMDIN_LOGIN = 0x0020,		//登录RecordServer验证指令
                        CMDIN_FORWARD,                  //转发用户指令
                        CMDIN_SESSION,			//与SessionServer交互的指令
                        CMDIN_ROOM,                     //与RoomServer交互的指令
                        CMDIN_OPLUS,                    //O+信息同步相关指令
                        CMDIN_ROOMASSISTANT,            //与RoomAssistant交互指令
                        CMDIN_LOGINS,                   //与LoginServer交互指令
                };
                enum {  //CMDIN_LOGIN
                        SCMDIN_LOGIN = 0x0001,		//请求登录RecordServer
                        SCMDIN_LOGIN_RESPONCE,		//登录RecordServer返回
                };
                enum {  //CMDIN_FORWARD
                        SCMDIN_FORWARD_TO_RA = 0x0001,   //转发用户执令到RA
                        SCMDIN_FORWARD_TO_USER,          //转发用户指令到客户端
                        SCMDIN_FORWARD_EXEC_CMD_TO_RA,  //转发redis命令到RA
                };
                enum {  //CMDIN_SESSION
                        SCMDIN_SESSION_UPDATE_USER_STATUS= 0x0001,      //更新用户的在线状态
                        SCMDIN_SESSION_NOTIFY_ALL_USER_STATUS,          //通知RAServer所有在线用户
                        SCMDIN_SESSION_NOTIFY_DEL_USER_TOKEN,           //通知RAServer删除用户Token
                        SCMDIN_SESSION_NOTIFY_OVERTIME_USER_TOKEN,      //通知RAServer延长用户Token时间
                };
                enum {  //CMDIN_ROOM
                        SCMDIN_ROOM_UPDATE_USER_NUM_REQ = 0x0001,       //请求更新某RoomServer上的房间的人数
                        SCMDIN_ROOM_UPDATE_USER_NUM_RES,                //更新房间人数
                        SCMDIN_ROOM_GET_USER_NUM_REQ,                   //请求房间的人数
                        SCMDIN_ROOM_GET_USER_NUM_RES,                   //请求房间的人数 返回
                        SCMDIN_ROOM_UPDATE_USER_ROLE,                   //房间用户的身份更新
                        SCMDIN_ROOM_UPDATE_USER_APPBITMASK,             //房间用户使用工具权限更新
                };
                enum {  //CMDIN_OPLUS
                        SCMDIN_OPLUS_SYNC_CLASS = 0x0001,               //同步O+课
                        SCMDIN_OPLUS_SYNC_USERS,                        //同步预约用户
                };
                enum {  //CMDIN_ROOMASSISTANT
                        SCMDIN_ROOM_CONFIG_CHANGE_REQ = 0x0001,         //请求房间配置变化
                        SCMDIN_ROOM_CONFIG_CHANGE_RES,                  //回复房间配置变化
                };
                enum {  //CMDIN_LOGINS
                        SCMDIN_LOGINS_NOTIFY_UPDATE_USER_TOKEN = 0x0001,        //通知RAServer更新用户Token
                };

                //	cmd definition
                struct stLoginCmd:t_NullCmd
                {
                        stLoginCmd():
                                t_NullCmd(CMDIN_LOGIN, SCMDIN_LOGIN)
                        {
                                dest_type_ = REDISADAPTERSERVER;
                                server_type_ = 0;
                                server_id_ = 0;
                        }
                        WORD dest_type_;
                        WORD server_type_;
                        DWORD server_id_;
                };
                struct stLoginResponce:t_NullCmd
                {
                        stLoginResponce():
                                t_NullCmd(CMDIN_LOGIN, SCMDIN_LOGIN_RESPONCE)
                        {
                        }
                };

                struct stForwardToRA:
                        t_NullCmd
                {
                        stForwardToRA():
                                t_NullCmd(CMDIN_FORWARD, SCMDIN_FORWARD_TO_RA)
                        {
                                user_id_ = 0;
                                size_ = 0;
                        }
                        DWORD user_id_;
                        WORD size_;
                        BYTE data_[0];
                        DWORD getSize() {
                                return sizeof(*this)+size_*sizeof(data_[0]);
                        }
                };
                struct stForwardToUser:
                        t_NullCmd
                {
                        stForwardToUser():
                                t_NullCmd(CMDIN_FORWARD, SCMDIN_FORWARD_TO_USER)
                        {
                                user_id_ = 0;
                                size_ = 0;
                        }
                        DWORD user_id_;
                        WORD size_;
                        BYTE data_[0];
                        DWORD getSize() {
                                return sizeof(*this)+size_*sizeof(data_[0]);
                        }
                };
                struct stForwardExecCmdToRA:
                        t_NullCmd
                {
                        stForwardExecCmdToRA():
                                t_NullCmd(CMDIN_FORWARD, SCMDIN_FORWARD_EXEC_CMD_TO_RA)
                        {
                                len = 0;
                        }
                        uint16_t len;
                        char command[0];
                        uint16_t get_size()
                        {
                                return sizeof(*this) + len*sizeof(command[0]);
                        }
                };

                struct stSessionUpdateUserStatus:
                        t_NullCmd
                {
                        stSessionUpdateUserStatus():
                                t_NullCmd(CMDIN_SESSION, SCMDIN_SESSION_UPDATE_USER_STATUS)
                        {
                                user_id_ = 0;
                                status_ = 0;
                        }
                        DWORD user_id_;
                        BYTE status_; //0-offline 1-online
                };
                struct stSessionNotifyAllUserStatus:
                        t_NullCmd
                {
                        stSessionNotifyAllUserStatus():
                                t_NullCmd(CMDIN_SESSION, SCMDIN_SESSION_NOTIFY_ALL_USER_STATUS)
                        {
                                user_num_ = 0;
                        }
                        DWORD user_num_;
                        DWORD user_list_[0];
                        DWORD getSize() {
                                return sizeof(*this)+user_num_*sizeof(user_list_[0]);
                        }
                };
                struct stSessionNotifyDelUserToken:
                        t_NullCmd
                {
                        stSessionNotifyDelUserToken():
                                t_NullCmd(CMDIN_SESSION, SCMDIN_SESSION_NOTIFY_DEL_USER_TOKEN)
                        {
                                user_id_ = 0;
                        }
                        
                        DWORD user_id_;
                };
                struct stSessionNotifyOvertimeUserToken:
                        t_NullCmd
                {
                        stSessionNotifyOvertimeUserToken():
                                t_NullCmd(CMDIN_SESSION, SCMDIN_SESSION_NOTIFY_OVERTIME_USER_TOKEN)
                        {
                                user_id_ = 0;
                                expire_sec_ = 0;
                        }

                        DWORD user_id_;
                        DWORD expire_sec_;
                };
                struct stRoomUpdateUserNumReq:
                        t_NullCmd
                {
                        stRoomUpdateUserNumReq():
                                t_NullCmd(CMDIN_ROOM, SCMDIN_ROOM_UPDATE_USER_NUM_REQ)
                        {
                        }
                };
                struct stRoomUpdateUserNumRes:
                        t_NullCmd
                {
                        stRoomUpdateUserNumRes():
                                t_NullCmd(CMDIN_ROOM, SCMDIN_ROOM_UPDATE_USER_NUM_RES)
                        {
                                size_ = 0;
                        }
                        WORD size_;
                        struct {
                                DWORD roomid;
                                DWORD usernum;
                        } list_[0];
                        DWORD getSize() {
                                return sizeof(*this)+size_*sizeof(list_[0]);
                        }
                };
                struct stRoomUpdateUserRole:
                        t_NullCmd
                {
                        public:
                                stRoomUpdateUserRole()
                                        : t_NullCmd(CMDIN_ROOM, SCMDIN_ROOM_UPDATE_USER_ROLE)
                                {
                                        room_id_ = 0;
                                        user_id_ = 0;
                                        role_ = 0;
                                }
                                void setRoomID(const DWORD &id)
                                {
                                        room_id_ = id;
                                }
                                void setUserID(const DWORD &id)
                                {
                                        user_id_ = id;
                                }
                                void setRole(const BYTE &role)
                                {
                                        role_ = role;
                                }
                                DWORD getRoomID() const
                                {
                                        return room_id_;
                                }
                                DWORD getUserID() const
                                {
                                        return user_id_;
                                }
                                BYTE getRole() const
                                {
                                        return role_;
                                }
                        private:
                                DWORD room_id_;
                                DWORD user_id_;
                                BYTE role_;
                };
                struct stRoomUpdateUserAppbitmask:
                        t_NullCmd
                {
                        stRoomUpdateUserAppbitmask()
                                : t_NullCmd(CMDIN_ROOM, SCMDIN_ROOM_UPDATE_USER_APPBITMASK)
                        {
                                room_id_ = 0;
                                user_id_ = 0;
                                appbitmask_ = 0;
                        }

                        uint32_t room_id_;
                        uint32_t user_id_;
                        uint32_t appbitmask_;
                };

                struct stOPlusSyncClass:
                        t_NullCmd
                {
                        stOPlusSyncClass():
                                t_NullCmd(CMDIN_OPLUS, SCMDIN_OPLUS_SYNC_CLASS)
                        {
                                num_ = 0;
                                finish_ = 0;
                        }
                        WORD num_;
                        BYTE finish_;   //0-no, 1-yes
                        struct {
                                char key[128];
                                DWORD classid;          //班级ID
                                DWORD roomid;           //房间ID
                                DWORD starttime;        //开课时间
                                DWORD endtime;          //结束时间
                                char name[MAX_OPLUS_NAME_SIZE + 1];
                        } classes_[0];
                        DWORD getSize() {
                                return sizeof(*this)+num_*sizeof(classes_[0]);
                        }
                };
                struct stOPlusSyncUsers:
                        t_NullCmd
                {
                        stOPlusSyncUsers():
                                t_NullCmd(CMDIN_OPLUS, SCMDIN_OPLUS_SYNC_USERS)
                        {
                                bzero(key_, sizeof(key_));
                                finish_ = 0;
                                num_ = 0;
                        }
                        char key_[128];
                        BYTE finish_;
                        WORD num_;
                        DWORD users_[0];
                        DWORD getSize() {
                                return sizeof(*this) + num_ * sizeof(users_[0]);
                        }
                };
                struct stRoomConfigChangeReq:
                        t_NullCmd
                {
                        stRoomConfigChangeReq():
                                t_NullCmd(CMDIN_ROOMASSISTANT, SCMDIN_ROOM_CONFIG_CHANGE_REQ)
                        {
                        }
                };
                struct stRoomConfigChangeRes:
                        t_NullCmd
                {
                        stRoomConfigChangeRes():
                                t_NullCmd(CMDIN_ROOMASSISTANT, SCMDIN_ROOM_CONFIG_CHANGE_RES)
                        {
                                size_ = 0;
                        }
                        WORD size_;
                        struct {
                                DWORD roomid;
                                WORD action;
                        } list_[0];
                        DWORD getSize() {
                                return sizeof(*this)+size_*sizeof(list_[0]);
                        }
                };
                struct stLoginsNotifyUpdateUserToken:
                        t_NullCmd
                {
                        stLoginsNotifyUpdateUserToken():
                                t_NullCmd(CMDIN_LOGINS, SCMDIN_LOGINS_NOTIFY_UPDATE_USER_TOKEN)
                        {
                                bzero(user_name_, sizeof(user_name_));
                                user_id_ = 0;
                                bzero(st_, sizeof(st_));
                                expire_sec_ = 0;
                        }
                        
                        char user_name_[MAX_ACCOUNT_SIZE+1];
                        DWORD user_id_;
                        char st_[MAX_TOKEN32_SIZE+1];
                        DWORD expire_sec_;
                };
        }; //namespace RedisAdapter
}; //namespace Cmd
#pragma pack() //pack(1)

#endif //REDISADAPTER_COMMAND_IN_H_
